<template>
 	<Layout class="p-5 bg-white">
		
		<h1>排课</h1>
 		<Form :label-width="90">
 			<FormItem class="w-50" label="课程编号">
				<Select v-model="course.courseId">
					<Option v-for="course in courses" :value="course.courseId">{{course.courseId}}</Option>
				</Select>
			 </FormItem>
 			<FormItem class="w-50" label="体训师编号" >
				<Select v-model="course.trainerId">
					<Option v-for="course in courses" :value="course.trainerId">{{course.trainerId}}</Option>
				</Select>
 		 	</FormItem>
 			<FormItem class="w-50" label="排课日期">
		 
			<input id="meeting" type="date" value="course.date"/>
			</FormItem>
 			<FormItem class="w-50" label="开始时间">	
	 
			<input id="meeting" @change="strTime" type="time" value="course.startTime"/>
			</FormItem>
 			<FormItem class="w-50" label="结束时间">
			<p>{{course.endTime}}</p>
		<!-- <input id="meeting" type="time" value="course.endTime"/> -->
			 </FormItem>
 			<FormItem class="text-right"> 
 				<Button @click="submit" type="primary">提交</Button>
 				<Button @click="cancel" class="ml-2">取消</Button>
 			</FormItem>
 		</Form>
 	</Layout>
 </template>
 <script>

     export default {
         data() {
             return {
 			 
                 course: {
                     courseId: "",
                     trainerId: "",
 					date: "",
 					price: "",
 					des: "",
 					typeId: "",
 					activeFlg: "",
 					delFlg: "",
 					count: "",
					startTime: "",
					endTime: ""
                 },
 				 
                 roles: [],
                 allRoles: [],
				 courses: []
                 // updateFlg: false,
                 // oldUser: {},
                 // oldRoles: [],
 
             }
         },
         methods: {
             cancel: function () {
                 this.$tabs.close();
             },
             submit: function () {
                 let self = this;
 				// self.user.openId = 0;
 				delete self.course.courseId;
 				delete self.course.name;
 				delete self.course.longs;
 				delete self.course.price;
 				delete self.course.des;
 				delete self.course.typeId;
 				delete self.course.activeFlg;
 				delete self.course.delFlg;
 				delete self.course.count;
 		 	
 				console.log(self.course);
                 this.http.put({
                     url: "/course/info",
                     param: self.course,
                 }).then(() => {
                     self.message.info("修改成功");
                 });
             },
             init: function () {
                 this.search();
				 this.getAllCourses();
				   
				 
             },
			 strTime: function(){
				  console.log(123);
				console.log(typeof(this.course.startTime));
				 this.course.endTime = this.course.startTime; 
			 },
			 getAllCourses: function() {
			 	this.http.get({
			 		url: "/course/schedule",
			 		param: {}
			 	}).then(data => {
			 		this.$data.courses = data.records;
			 	});
			 },
             searchUser: function () {
                 let self = this;
 
                 this.http.get({
                     url: "/course/schedule",
                     param: {
                         courseId: self.$data.course.courseId
                     }
                 }).then(data => {
                     console.log(data);
 					self.course = data.course;
 					for (let jndex in self.allRoles) {
 						let role = self.allRoles[jndex];
 						role.has = false;
 						for (let index in data.roles) {
 							let roleItem = data.roles[index];
 							if (roleItem.roleId == role.roleId) {
 								role.has = true;
 								this.roles.push(role);
 							}
 						}
 					}
 					
                 });
             },
 
             search: function () {
                 let self = this;
                 this.http.get({
                     url: "/role/all",
                 }).then(data => {
                     self.$data.allRoles = data;
                 })
				 // .then(() => {
     //                 self.searchUser();
     //             })
				 ;
             }
 
         },
 
         created: function () {
         },
         mounted: function () {
 			this.$data.course.courseId = this.$route.params.courseId;
             this.init();
         }
     }
 </script>
 
 <style>
 </style>
 